package com.cjg.tvolatier;

import java.util.concurrent.atomic.AtomicInteger;

public class demo02 {
    static AtomicInteger anInt=new AtomicInteger();
    public static void main(String[] args) {
        for (int i = 0; i <20 ; i++) {
            new Thread(() -> {
                for (int j = 0; j < 2000; j++) {
                    add();
                }
            }).start();
        }
        while (Thread.activeCount()>2){
            Thread.yield();
        }


        System.out.println(anInt);
    }

    public static void add(){

        anInt.getAndIncrement();
    }
}
